import streamlit as st
from index import save ,authenticator
# import streamlit_authenticator as stauth
# import yaml

from streamlit_authenticator.utilities.exceptions import (CredentialsError,
                                                          ForgotError,
                                                          LoginError,
                                                          RegisterError,
                                                          ResetError,
                                                          UpdateError) 
# with open('st_auth/config.yaml') as file:
#     config = yaml.load(file, Loader=yaml.SafeLoader)
    
# authenticator = stauth.Authenticate(
#     config['credentials'],
#     config['cookie']['name'],
#     config['cookie']['key'],
#     config['cookie']['expiry_days'],
#     config['pre-authorized']
# )
def forgot_pwd():
    try:
        (username_of_forgotten_password,
            email_of_forgotten_password,
            new_random_password) = authenticator.forgot_password()
        if username_of_forgotten_password:
            st.success('New password sent securely')
            st.write(new_random_password)
            save()
        elif not username_of_forgotten_password:
            st.error('Username not found')
    except ForgotError as e:
        st.error(e)
        
# def save():
#      with open('st_auth/config.yaml', 'w', encoding='utf-8') as file:
#          yaml.dump(config, file, default_flow_style=False)
         
         
if __name__ == '__main__':
    forgot_pwd()